
import 'package:get/get.dart';

/*
  请求url--> + https://api.huanxindj.top/apiV1/chat/send
       请求header-> {"content-type":"application/json","os-type":"ios","version":"1.0.2","build":"43","packageid":"com.example.hxdj","app-type":"huanxindj","timestamp":1721101527410826,"lon":"121.190355","lat":"31.287705","city":"%E4%B8%8A%E6%B5%B7%E5%B8%82","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI3NjM1ZWEyYzNmMDRkZWViYzczNTdmMDE5NWY0OGZiOSIsImF1ZCI6IiIsImlhdCI6MTcyMTA5MzA5NiwibmJmIjoxNzIxMDkzMDk2LCJleHAiOjE3MjM2ODUwOTYsImRhdGEiOnsibWVtYmVyX2lkIjo1MzksIm1vYmlsZSI6IjE4NTk1OTYxNzg4In19.KTfjuMlZ6Blx3yC-8SBWcN27o-Lon58qOlnpV-l76IE"}
       请求参数-> + {"message_type":"RC:TxtMsg","content":"v123","receive_im_user":"huanxindjt12418"} 
       开始时间 == 27秒411
[log] 返回的url是chat/send
      结束时间->27秒754
      {"code":0,"msg":"成功","data":{"chat_times":40}}
 */
class MyBaseHttp extends GetConnect {
  @override
  void onInit() {
    httpClient.baseUrl = "http://ft1-superapp-oss.oss-cn-shenzhen.aliyuncs.com/ecommerce-json";
    // 请求拦截
    httpClient.addRequestModifier<void>((request) {
      Map<String, String> headerMap = {
        "os-type": GetPlatform.isIOS ? "ios" : "android",
        "version": "1.0.2",
        "build": "43",
        "packageid": "com.example.hxdj",
        'app-type': "huanxindj",
        "timestamp": DateTime.now().microsecondsSinceEpoch.toString(),
      };
      request.headers.addAll(headerMap);

      return request;
    });

    // 响应拦截
    httpClient.addResponseModifier((request, response) {

    //   Map<String, dynamic> jsonMap = jsonDecode(response.data ?? {});
    // DateTime endDateTime = DateTime.now();

    // var statusCode = jsonMap["code"];

    // if (statusCode == "success" || statusCode == 0 || statusCode == "0" || statusCode == "200") {
    //   Map resultMap = jsonDecode(response.data);
    //   log("返回的url是${response.requestOptions.path.toString()}\n结束时间->${endDateTime.second}秒${endDateTime.millisecond}\n${json.encode(resultMap).toString()}");
    // } else {
    //   log("这里接口报错了返回的url是${response.requestOptions.path.toString()}\n结束时间->${endDateTime.second}秒${endDateTime.millisecond}\n返回参数->${jsonDecode((response.data))}");
    // }

      return response;
    });
  }
}
